package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerElectricianCertificateMapper;
import com.hig.ledger.domain.LedgerElectricianCertificate;
import com.hig.ledger.service.ILedgerElectricianCertificateService;

/**
 * 电工证统计Service业务层处理
 *
 * @author scp
 * @date 2024-09-22
 */
@Service
public class LedgerElectricianCertificateServiceImpl implements ILedgerElectricianCertificateService
{
    @Autowired
    private LedgerElectricianCertificateMapper ledgerElectricianCertificateMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询电工证统计
     *
     * @param id 电工证统计ID
     * @return 电工证统计
     */
    @Override
    public LedgerElectricianCertificate selectLedgerElectricianCertificateById(Long id)
    {
        return ledgerElectricianCertificateMapper.selectLedgerElectricianCertificateById(id);
    }

    /**
     * 查询电工证统计列表
     *
     * @param ledgerElectricianCertificate 电工证统计
     * @return 电工证统计
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerElectricianCertificate> selectLedgerElectricianCertificateList(LedgerElectricianCertificate ledgerElectricianCertificate)
    {
        return ledgerElectricianCertificateMapper.selectLedgerElectricianCertificateList(ledgerElectricianCertificate);
    }

    /**
     * 新增电工证统计
     *
     * @param ledgerElectricianCertificate 电工证统计
     * @return 结果
     */
    @Override
    public int insertLedgerElectricianCertificate(LedgerElectricianCertificate ledgerElectricianCertificate)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerElectricianCertificate.setCreateBy(loginUser.getUser().getUserName());
        ledgerElectricianCertificate.setDeptId(loginUser.getUser().getDeptId());
//        long id = ledgerElectricianCertificateMapper.getNextId();
//        ledgerElectricianCertificate.setId(id);
        ledgerElectricianCertificate.setCreateTime(DateUtils.getNowDate());
        return ledgerElectricianCertificateMapper.insertLedgerElectricianCertificate(ledgerElectricianCertificate);
    }

    /**
     * 修改电工证统计
     *
     * @param ledgerElectricianCertificate 电工证统计
     * @return 结果
     */
    @Override
    public int updateLedgerElectricianCertificate(LedgerElectricianCertificate ledgerElectricianCertificate)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerElectricianCertificate.setUpdateBy(loginUser.getUser().getUserName());
        ledgerElectricianCertificate.setUpdateTime(DateUtils.getNowDate());
        return ledgerElectricianCertificateMapper.updateLedgerElectricianCertificate(ledgerElectricianCertificate);
    }

    /**
     * 批量删除电工证统计
     *
     * @param ids 需要删除的电工证统计ID
     * @return 结果
     */
    @Override
    public int deleteLedgerElectricianCertificateByIds(Long[] ids)
    {
        return ledgerElectricianCertificateMapper.deleteLedgerElectricianCertificateByIds(ids);
    }

    /**
     * 删除电工证统计信息
     *
     * @param id 电工证统计ID
     * @return 结果
     */
    @Override
    public int deleteLedgerElectricianCertificateById(Long id)
    {
        return ledgerElectricianCertificateMapper.deleteLedgerElectricianCertificateById(id);
    }
}
